using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Helpers
{
    public static class QueryStringHelper
    {
        public static bool TryGetString(string queryStringParam, out string returnValue)
        {
            string value = HttpContext.Current.Request.QueryString[queryStringParam];
            if (value != null)
            {
                returnValue = value;
                return true;
            }
            else
            {
                returnValue = null;
                return false;
            }
        }

        public static bool TryGetInt32(string queryStringParam, out int returnValue)
        {
            string queryStringValue;
            if (TryGetString(queryStringParam, out queryStringValue))
            {
                return Int32.TryParse(queryStringValue, out returnValue);
            }
            else
            {
                returnValue = Int32.MinValue;
                return false;
            }
        }

        public static bool TryGetInt64(string queryStringParam, out long returnValue)
        {
            string queryStringValue;
            if (TryGetString(queryStringParam, out queryStringValue))
            {
                return Int64.TryParse(queryStringValue, out returnValue);
            }
            else
            {
                returnValue = Int64.MinValue;
                return false;
            }
        }

        public static bool TryGetDateTime(string queryStringParam, out DateTime returnValue)
        {
            string queryStringValue;
            if (TryGetString(queryStringParam, out queryStringValue))
            {
                return DateTime.TryParse(queryStringValue, out returnValue);
            }
            else
            {
                returnValue = DateTime.MinValue;
                return false;
            }
        }
    }
}